
***********************
**PLOT RELATING AFFIDIAVIT AND SUSTAIN LOMS
***********************

**Average supervisor effects
sort inv_id
by inv_id: egen sup_affidavit = mean(lom_treat_affidavit)
by inv_id: egen sup_sustain = mean(lom_treat_sustain)
by inv_id: gen sup_plot_mark = _n==1

list inv_id inv_ct sup_affidavit sup_sustain if sup_plot_mark==1

twoway ///
(scatter sup_affidavit sup_sustain if sup_plot_mark==1) ///
(lfit sup_affidavit sup_sustain), ///
xlabel(-0.3(0.05)0.3) ylabel(-0.3(0.05)0.3)  ///
xtitle("Mean Sustain LOM", size(medlarge)) ytitle("Mean Affidavit LOM", size(medlarge)) ///
legend(order (2 "Case-Weighted Correlation")) graphregion(fcolor(white) color(white) icolor(white)) scheme( s1color  )
graph export ${rep_root}/output/figures/lom_correlation.pdf, replace



***********************
**PLOT OF AFFIDIAVIT AND SUSTAIN LOMS EACH YEAR
***********************


collapse lom_treat_affidavit lom_treat_sustain, by(inv_id intake_yr)
scatter lom_treat_affidavit lom_treat_sustain intake_yr, by(inv_id, note("")) xtitle("Year", size(medlarge)) ytitle("Mean LOM", size(medlarge)) legend(order (1 "Affidavit" 2 "Sustain")) graphregion(fcolor(white) color(white) icolor(white)) scheme(s1color)
graph export ${rep_root}/output/figures/lom_yby.pdf, replace
 

sort inv_id intake_yr
by inv_id: gen first_yr = intake_yr[1] 
gen tenure = intake_yr - first_yr 

sum lom_treat_affidavit, d



foreach var of varlist lom_treat_affidavit lom_treat_sustain{
eststo: areg `var' tenure, a(inv_id) cluster(inv_id)
 

	
local beta`var' = _b[tenure]
 	
boottest tenure, weight(webb)  nograph seed(9999)
local p`var' = r(p)
display r(p)


//get stars based on bootstrapped p values 
glo star_`var' = cond(`p`var'' <0.01, "***", cond(`p`var'' <0.05, "**", cond(`p`var'' <0.1, "*", "")))
local p`var' : di %6.3f `p`var'' 

matrix b`var' = e(b)
matrix v`var' = e(V)
scalar N= e(N)
local N`var' = N


local se`var' = sqrt(v`var'[1,1])

local beta`var' : di %6.3f `beta`var''
local se`var' : di %6.3f `se`var''
local N`var' : di %7.0fc `N`var''



sum `var'
local sd_`var' =r(sd)
local sd_`var' : di %6.2f `sd_`var''
}	 

 
 
texdoc init ${rep_root}/output/tables/lom_yby.tex, replace force
tex \begin{tabular}{l*{2}{c}}
tex \hline\hline
tex                     &\multicolumn{1}{c}{Affidavit LOM}&\multicolumn{1}{c}{Sustain LOM}& \\
tex \hline
  
tex Tenure  & `betalom_treat_affidavit'${star_lom_treat_affidavit} & `betalom_treat_sustain'${star_lom_treat_sustain}  \\
tex          & (`selom_treat_affidavit') & (`selom_treat_sustain')   \\
tex   & [`plom_treat_affidavit']& [`plom_treat_sustain']  \\ 
tex Dep. var. SD & `sd_lom_treat_affidavit'&`sd_lom_treat_sustain' \\
tex Observations & `Nlom_treat_affidavit'&`Nlom_treat_sustain'   \\   
tex \hline\hline
tex \end{tabular}
texdoc close

 